
/**
 * This class represents a measure received by a client. A measure is represented by:
 * <ul>
 *   <li>A start date and time
 *   <li>An end date and time
 *   <li>An machine hostname on which the measure has been taken
 *   <li>A username, which corresponds on the logged user on the machine where the measure has been taken
 *   <li>A mean electrical power consumption
 *   <li>A peak electrical power consumption
 * </ul>
 * <p>
 * The date and time has the next format: YYYY-MM-DD HH:MM:SS
 * @author Alexandre Dos Santos Coelho
 */
public class Measure {

  private String start; // Start date & time
  private int duration; // End date & time
  private String machineId; // Hostname on which the measure has been taken
  private String machineType; // Machine model
  private String userName; // User logged on the machine where measure has been taken
  private float consumption; // Mean electrical power consumption

  /**
   * Constructor. Creates a measure with its attributes
   * @param input
   * @param machineId
   */
  public Measure(String[] input, String machineId, String machineType) {
    try {
      // Extracting values
      start = input[1];
      duration = Integer.valueOf(input[2]);
      this.machineId = machineId;
      consumption = Float.valueOf(input[3]);
      userName = input[4];
      this.machineType = machineType;
    } catch (Exception e) {
      System.err.println(Logger.getTime() + "Impossible to build Measure");
    }
  }

  /**
   * Returns a string which presents all of the measure attributes
   * @return
   */
  @Override
  public String toString() {
    return "Received measure from " + getMachineId() + "(logged user: " + getUserName() +
            ", machine type: "+machineType+"), start: " + getStart() +
            ", duration: " + getDuration() + ", mean consumption: " + getConsumption();
  }

  /**
   * @return the start date & time
   */
  public String getStart() {
    return start;
  }

  /**
   * @param start the start date & time
   */
  public void setStart(String start) {
    this.start = start;
  }

  /**
   * @return the end date & time
   */
  public int getDuration() {
    return duration;
  }

  /**
   * @param end the end date & time
   */
  public void setDuration(int end) {
    this.duration = end;
  }

  /**
   * @return the machine hostname
   */
  public String getMachineId() {
    return machineId;
  }

  /**
   * @param machineId the machine hostname
   */
  public void setMachineId(String machineId) {
    this.machineId = machineId;
  }

  /**
   * @return the mean consumption
   */
  public float getConsumption() {
    return consumption;
  }

  /**
   * @param consumption the mean consumption
   */
  public void setConsumption(float consumption) {
    this.consumption = consumption;
  }

  /**
   * @return logged user on machine
   */
  public String getUserName() {
    return userName;
  }

  /**
   * @param userName logged user on machine
   */
  public void setUserName(String userName) {
    this.userName = userName;
  }

  /**
   * @return the machineType
   */
  public String getMachineType() {
    return machineType;
  }

  /**
   * @param machineType the machineType to set
   */
  public void setMachineType(String machineType) {
    this.machineType = machineType;
  }
}
